package servlet;

import entity.Orgnazition;
import service.OrgnazitionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int status = Integer.parseInt(req.getParameter("status"));
        String name = req.getParameter("name");

        OrgnazitionService orgnazitionService = new OrgnazitionService();
        int update = 0;
        if(status==1){
            update = orgnazitionService.Update(0, name);
        }else{
            update = orgnazitionService.Update(1, name);
        }
        PrintWriter out = resp.getWriter();
        if(update>0){
            out.print(true);
        }else{
            out.print(false);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
